#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include "lang.h"
#include "resource.h"
#include "func.h"
#include "com.h"
#include "mhstatic.h"


static int MhStaticProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case MSG_CREATE:
        {
        }
        break;
    case MSG_PAINT:
        {
        }
        break;
    case MSG_LBUTTONDOWN:
        {
            if(GetCapture() == hWnd)
            {
                break;
            }
            SetCapture(hWnd);
        }
        break;
    case MSG_LBUTTONUP:
        {
            if(GetCapture() != hWnd)
            {
                break;
            }
            ReleaseCapture();
            NotifyParent(hWnd, GetDlgCtrlID(hWnd), EN_CLICKED);
        }
        break;
    case MSG_DESTROY:
        {
        }
        break;
    case MSG_ERASEBKGND:
        {
            BITMAP *p = (BITMAP*)GetWindowAdditionalData(hWnd);
            if(p)
            {
                RECT rect;
                GetClientRect(hWnd, &rect);
                int nWidth = GET_RECT_WIDTH(rect);
                int nHeight = GET_RECT_HEIGHT(rect);
                HDC hdc = GetClientDC(hWnd);
                FillBoxWithBitmap (hdc, rect.left, rect.top, nWidth, nHeight, p);
                ReleaseDC(hdc);
            }
        }
        return 0;
    }

    return DefaultControlProc (hWnd, message, wParam, lParam);
}

BOOL RegisterMhStatic (void)
{
    WNDCLASS MyClass;

    MyClass.spClassName = MH_STATIC_NAME;
    MyClass.dwStyle     = WS_NONE;
    MyClass.dwExStyle   = WS_EX_NONE;
    MyClass.hCursor     = GetSystemCursor (IDC_ARROW);
    MyClass.iBkColor    = COLOR_lightwhite;
    MyClass.WinProc     = MhStaticProc;
    return RegisterWindowClass (&MyClass);
}

void UnregisterMhStatic (void)
{
    UnregisterWindowClass (MH_STATIC_NAME);
}
